﻿using System.Collections.Generic;
using System.Web.Mvc;
using ClientLibrary;
using NewsCrawler.Common.Models;
using System;
using System.Text;

namespace Site.Code.HtmlHelpers
{
    public static class CategoryHelper
    {
        public static MvcHtmlString CategoriesFor(this HtmlHelper htmlHelper, List<Category> categories)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var category in categories)
            {
                sb.AppendLine(string.Format("<li class='bgr'><a href=\"{0}\">{1}</a></li>", "Category/" + category.Name, category.Name));
            }
            return new MvcHtmlString(sb.ToString());
        }

        public static MvcHtmlString CategoryLabelModeFor(this HtmlHelper htmlHelper, Category category)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<div id=\"category\">");

            sb.AppendLine(string.Format("Name: {0} <br />", category.Name));
            sb.AppendLine(string.Format("Description: {0} <br />", category.Description));
            sb.AppendLine(string.Format("Culture: {0} <br />", category.CultureCode));
            sb.AppendLine(string.Format("Id: {0} <br />", category.CategoryId));

            sb.AppendLine("</div>");
            return new MvcHtmlString(sb.ToString());
        }

        public static MvcHtmlString FlashNews(this HtmlHelper htmlHelper, List<Article> news)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<div id=\"flashnews\">");
            foreach (var item in news)
            {
                sb.AppendLine(string.Format("<p><a href=\"{0}\">{1}</a><br />{2}</p>",
                                            string.Format("News/{0}", item.Title), item.Title, item.Summary));
            }
            sb.AppendLine("</div>");
            return new MvcHtmlString(sb.ToString());
        } 

        public static MvcHtmlString NewsByCategoryId(this HtmlHelper htmlHelper, string categoryId)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<div id=\"categorynews\">");
            var news = Core.Instance.Repository.GetNewsByCategoryId(categoryId);
            foreach (var item in news)
            {
                sb.AppendLine(string.Format("<p><a href=\"{0}\">{1}</a><br />{2}</p>",
                                            string.Format("News/{0}", item.Title), item.Title, item.Summary));
            }
            sb.AppendLine("</div>");
            return new MvcHtmlString(sb.ToString());
        } 
    }
}